﻿<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:rs="urn:schemas-microsoft-com:rowset"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:z="#RowsetSchema">
	<xsl:template match="/">

		<link rel="stylesheet" type="text/css" href="/Style Library/EnhancedCQWP/Css/Rollups.css" title="Style">
			<xsl:comment>Comment added so script is recognised</xsl:comment>
		</link>
		
		<div class="ECRollup">
			<ul class="ECGroup">

				<xsl:if test="count(/Pages/Page) = 0">
					<div>
						0 items.
					</div>
				</xsl:if>

				<xsl:for-each select="/Pages/Page[not(@Metadata=preceding-sibling::Page/@Metadata)]">
					<xsl:sort select="substring(@Metadata,3)" order="ascending"/>
					<xsl:variable name="CategoryNorm" select="@Metadata" />
					<xsl:variable name="beforeTerm" select="substring-before($CategoryNorm, '|')" />
					<xsl:variable name="term" select="substring-after($beforeTerm, '#')" />

					<li>
						<h2>
							<xsl:value-of select="$term"/>
						</h2>

						<ul class="pages">
							<xsl:for-each select="/Pages/Page[@Metadata=$CategoryNorm]">
								<xsl:sort select="@LastModifiedDate" order="descending"/>
								<li>
									<span class="pageTitle">
										<a class="rolluplink">
											<xsl:attribute name="href">
												<xsl:value-of select="@AbsolutePath"/>
											</xsl:attribute>
											<span>
												<xsl:value-of select="@Title"/>
											</span>
										</a>
									</span>
									<span class="pubDateTime">
										<xsl:value-of select="ddwrt:FormatDateTime(string(@LastModifiedDate) ,1043,'d MMMM yyyy')"/>
									</span>
								</li>
							</xsl:for-each>
						</ul>
					</li>
				</xsl:for-each>
			</ul>
		</div>
	</xsl:template>
</xsl:stylesheet>
